package kr.co.mcshop.qnacomment;

import java.util.Locale;
import java.util.Map;

import kr.co.mcshop.qna.QnAController;
import kr.co.mcshop.qnareply.QnAReplyService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@RequestMapping(value = "/QnA")
@Controller
public class QnACommentController {
	private static final Logger logger = LoggerFactory
			.getLogger(QnAController.class);

	@Autowired
	private QnACommentService qnacommentService;
	@Autowired
	private QnAReplyService qnareplyService;
	
	
	
	@RequestMapping(value = "/qnacommentInsert", method = RequestMethod.POST)
	public String qnacommentInsert(Locale locale, Model model, @RequestParam Map map) {

		System.out.println(map);
		map.get("user_id");
		qnacommentService.qnacommentInsert(map);
		return "redirect:/QnA/QnA_detail?board_no="+map.get("board_no");
	}
	
	@RequestMapping(value = "/qnacommentUpdate", method = RequestMethod.POST)
	public String qnacommentupdate(Locale locale, Model model, @RequestParam Map map) {
		System.out.println(map);
		qnacommentService.updateqnacomment(map);
		return "redirect:/QnA/QnA_detail?board_no="+map.get("board_no");
	}
	
	@RequestMapping(value = "/qnacommentDelete", method = RequestMethod.GET)
	public String qnacommentDelete(Model model, @RequestParam Map map, Integer board_no) {
		System.out.println(board_no);
		qnacommentService.qnacommentDelete(map);
		qnareplyService.faqreplyDelete(map);
		return "redirect:/QnA/QnA_detail?board_no="+board_no;
	}
}
